Урок 3. Введение в Docker (https://gb.ru/lessons/443731)

https://docs.docker.com/engine/install/ubuntu/

# Uninstall old versions
sudo apt-get remove docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc

# Uninstall all conflicting packages:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

# установим пару пакетов, которые назначат право для “apt” пользоваться пакетами по протоколу HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

# Install the Docker packages
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

#####################################

docker --version
Docker version 26.1.4, build 5650f9b

docker info
Client: Docker Engine - Community
 Version:    26.1.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 1
 Server Version: 26.1.4
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d2d58213f83a351ca8f528a95fbd145f5654e957
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-35-generic
 Operating System: Ubuntu 24.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.778GiB
 Name: ki
 ID: b8f22705-f8f4-4bb2-a380-3cb5127d8c2f
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

# List images
docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   13 months ago   13.3kB

# Remove all images
docker rmi $(docker images -aq) --force

# List container
docker ps -a
CONTAINER ID   IMAGE          COMMAND    CREATED          STATUS                      PORTS     NAMES
a62778454860   d2c94e258dcb   "/hello"   39 minutes ago   Exited (0) 39 minutes ago             goofy_wilbur

# Запуск контейнера в интерактивном режиме (-it)
docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
00d679a470c4: Pull complete
Digest: sha256:e3f92abc0967a6c19d0dfa2d55838833e947b9d74edbcb0113e48535ad4be12a
Status: Downloaded newer image for ubuntu:latest
root@2298522754da:/#

exit

# Запуск nginx

docker run --publish 8080:80 nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
09f376ebb190: Pull complete
5529e0792248: Pull complete
9b3addd3eb3d: Pull complete
57910a8c4316: Pull complete
7b5f78f21449: Pull complete
b7923aa4e8a6: Pull complete
785625911f12: Pull complete
Digest: sha256:0f04e4f646a3f14bf31d8bc8d885b6c951fdcf42589d06845f64d18aec6a3c4d
Status: Downloaded newer image for nginx:latest
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/06/09 09:10:25 [notice] 1#1: using the "epoll" event method
2024/06/09 09:10:25 [notice] 1#1: nginx/1.27.0
2024/06/09 09:10:25 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2024/06/09 09:10:25 [notice] 1#1: OS: Linux 6.8.0-35-generic
2024/06/09 09:10:25 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/06/09 09:10:25 [notice] 1#1: start worker processes
2024/06/09 09:10:25 [notice] 1#1: start worker process 29
2024/06/09 09:10:25 [notice] 1#1: start worker process 30
2024/06/09 09:10:25 [notice] 1#1: start worker process 31
2024/06/09 09:10:25 [notice] 1#1: start worker process 32

# Запуск nginx в режиме демона
docker run -d --publish 8080:80 nginx
ae04982a851b4e2b82e2c9b27cc22369f4b1cf6d3cef9b225df28897f221ac08

curl 127.0.0.1:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

# remove container
docker rm $(docker ps -a -q)
e322761e0486
2298522754da
a62778454860
Error response from daemon: cannot remove container "/agitated_thompson": container is running: stop the container before removing or force remove

docker rm $(docker ps -a -q) --force
ae04982a851b

docker run -d ubuntu
c03c44b1395e7e9a9ad23fc7af4166d0621fa8ccd18a8043667f87d5dee97f25

docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES
c03c44b1395e   ubuntu    "/bin/bash"   23 seconds ago   Exited (0) 22 seconds ago             nostalgic_kilby

docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          2         1         263.9MB   187.7MB (71%)
Containers      1         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

# Очистка диска (удаление образов и остановленных контейнеров)
docker system prune -af
Deleted Containers:
c03c44b1395e7e9a9ad23fc7af4166d0621fa8ccd18a8043667f87d5dee97f25

Deleted Images:
untagged: ubuntu:latest
untagged: ubuntu@sha256:e3f92abc0967a6c19d0dfa2d55838833e947b9d74edbcb0113e48535ad4be12a
deleted: sha256:17c0145030df106e60e5d99149d69810db23b869ff0d3c9d236279a5a7bbb6b3
deleted: sha256:42d3f8788282c6e48bac7236609753b240db353465dc55cb77c21f2391720dd9
untagged: nginx:latest
untagged: nginx@sha256:0f04e4f646a3f14bf31d8bc8d885b6c951fdcf42589d06845f64d18aec6a3c4d
deleted: sha256:4f67c83422ec747235357c04556616234e66fc3fa39cb4f40b2d4441ddd8f100
deleted: sha256:61eeae0da48f3cc48ebf1d0a192ad8f19cb6c6ed67d0f0a7ef1f1c443c1effd7
deleted: sha256:5cde5b697c8179331355ba55c3754bb565e74b9c84170f398a736e29e8ece1f8
deleted: sha256:8f957df28f8990c12af00f83cbc17560d57284835f695e3b1c2a39d22f6b117d
deleted: sha256:4421830dc9390171c909a2beb619a00bb2c4a1fb8f7e187b14a38e1f84aa76db
deleted: sha256:b25c84fbc54990754cb7662c5f299f2e44700731f5f19e610f61eb7348c2c2fc
deleted: sha256:23b17aa4ac172d8d931417d0c681ea8f94d26e353a3f9d2d3cc75e01fed6d99e
deleted: sha256:5d4427064ecc46e3c2add169e9b5eafc7ed2be7861081ec925938ab628ac0e25

Total reclaimed space: 263.9MB


docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          0         0         0B        0B
Containers      0         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B
